package cc.lucien.service;

import cc.lucien.entity.BarVO;
import cc.lucien.entity.GoodsBarVO;
import cc.lucien.entity.PieVO;
import cc.lucien.repository.DataRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DataService {

    @Autowired
    private DataRepository dataRepository;

    public BarVO getBarVO() {
        List<GoodsBarVO> list = dataRepository.findAllGoodsBarVO();
        List<String> names = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        for (GoodsBarVO goodsBarVO : list) {
            names.add(goodsBarVO.getName());
            values.add(goodsBarVO.getCount());
        }
        BarVO barVO = new BarVO();
        barVO.setNames(names);
        barVO.setValues(values);
        return barVO;
    }

    public List<PieVO> getPieVO() {
        return dataRepository.findAllGoodsPieVO();
    }
}
